/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agenda.model;

import com.agenda.model.entity.AmTbAgenMedi;
import com.agenda.model.persistence.DAOFactory;
import com.agenda.model.repository.AgendaRepository;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Ronildo
 */

@Stateless
@WebService(serviceName = "AgendaBOImpl")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class AgendaBOImpl implements AgendaBO{
    
    @PersistenceContext
    private EntityManager em;
    private AgendaRepository agendaRepository;
    
    @PostConstruct
    public void initialize(){
        agendaRepository = DAOFactory.getAgendaRepository(em);
    }
    
    @WebMethod
    public void insertAgenda(@WebParam(name = "agenda")AmTbAgenMedi agenda){
        agendaRepository.persist(agenda); 
    }
    
    @WebMethod
    public void deleteAgenda(@WebParam(name = "agenda")AmTbAgenMedi agenda){
        agendaRepository.remove(agenda, agenda.getNrSequAgenMedi());
    }
    
    @WebMethod
    public void updateAgenda(@WebParam(name = "agenda")AmTbAgenMedi agenda){
        agendaRepository.update(agenda);
    }
    
    @WebMethod
    public AmTbAgenMedi findAgendaById(@WebParam(name = "id")Long id){
        return agendaRepository.findById(id);
    }
    
    @WebMethod
    public List<AmTbAgenMedi> listAgenda(@WebParam(name = "agenda")AmTbAgenMedi agenda){
        return agendaRepository.list(agenda);
    }
    
}
